# A setup script showing how to extend py2exe.
#
# In this case, the py2exe command is subclassed to create an installation
# script for InnoSetup, which can be compiled with the InnoSetup compiler
# to a single file windows installer.
#
# By default, the installer will be created as dist\Output\setup.exe.

from distutils.core import setup
import py2exe
import os

################################################################
# A program using wxPython

# The manifest will be inserted as resource into test_wx.exe.  This
# gives the controls the Windows XP appearance (if run on XP ;-)
#
# Another option would be to store if in a file named
# test_wx.exe.manifest, and probably copy it with the data_files
# option.
#
manifest_template = '''
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity
    version="5.0.0.0"
    processorArchitecture="x86"
    name="%(prog)s"
    type="win32"
/>
<description>%(prog)s Program</description>
<dependency>
    <dependentAssembly>
        <assemblyIdentity
            type="win32"
            name="Microsoft.Windows.Common-Controls"
            version="6.0.0.0"
            processorArchitecture="X86"
            publicKeyToken="6595b64144ccf1df"
            language="*"
        />
    </dependentAssembly>
</dependency>
</assembly>
'''

RT_MANIFEST = 24

################################################################
# arguments for the setup() call

PyShare_wx = dict(
    script = "PyShareUI.pyw",
    other_resources = [(RT_MANIFEST, 1, manifest_template % dict(prog="PyShare"))],
    dest_base = r"prog\PyShare_wx")

zipfile = None#r"lib\sharedlib.zip"

#from distutils.file_util import copy_file
#from distutils.dir_util import mkpath

#def gather_data_files(module, base_dir):
#    s = []
#    mod = __import__(module, [], [], [''])
#    path = mod.__path__[0]
#    length = len(os.path.dirname(path)) + 1 #include os.sep
#    
#    for root, dirs, files in os.walk(path):
#        for f in files:
#            fname, ext = os.path.splitext(f)
#            if ext not in ('.py', '.pyc', '.pyo'):
#                filename = os.path.join(root, f)
#                desfname = filename[length:]
#                sfilename = os.path.join(base_dir, desfname)
#                mkpath(os.path.dirname(sfilename))
#                copy_file(filename, os.path.join(base_dir, desfname))
#                s.append(desfname)
#    return s

includes = ["cn.*"]
#packages = ["docutils"]
options = {
        "py2exe":
        {
                "compressed": 1,
                "optimize": 2,
                "includes": includes,
                "bundle_files": 1,
#                "packages": packages,
        }
}
    
    
setup(
        version = '0.1',
        description = "PyShare",
        name = "PyShare",
        author = "Ant-man",
        author_email="antmanler@gmail.com",

        options = options,
        # The lib directory contains everything except the executables and the python dll.
        zipfile = zipfile,
        windows = [
                {
                        "script":"PyShareUI.pyw",
#                        "icon_resources": [(1, "PyShare.ico")]
                }
        ],
        other_resources = [(RT_MANIFEST, 1, manifest_template % dict(prog="PyShare"))],
#        data_files = [
#                ('', ['PyShare.ico', 'COPYLEFT.txt', 'INFO.txt', 'PyShare.exe.manifest']),
#        ]
    )

if os.path.exists('PyShareUI.exe.manifest'):
    
    f = open('PyShareUI.exe.manifest', 'w')
    f.write(manifest_template % dict(prog="PyShare"))
